<template>
    <el-dialog
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :show-close="false"
        title="导入货品"
        :visible.sync="dialogVisible"
        width="50%"
    >
        <base-table
            ref="GoodsTable"
            :tableData="gridData"
            :colunmData="colunmData"
            class="size-table pdb-8"
            :tableConfig="tableConfig"
            @select="selectRow"
        />
        <span slot="footer" class="dialog-footer">
            <el-button @click="unImport">不导入</el-button>
            <el-button type="primary" @click="importData">导入</el-button>
        </span>
    </el-dialog>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { TableHeaderConfig } from '@/typings';
import { Prop } from 'vue-property-decorator';
import { Dictionary } from '@/typings';
@Component({
    name: 'ImportGoodsDialog',
    components: {
        baseTable: () => import('@/components/base-table/index.vue')
    }
})
export default class App extends Vue {
    @Prop({ required: true }) colunmData: TableHeaderConfig[];
    // @Prop({ required: true }) prevBillConfig: Dictionary<string>
    dialogVisible: boolean = false;
    prevBillDetail: Dictionary = {};
    gridData: any[] = [];
    selectArray: any[] = [];
    importControls: Function;
    tableConfig: any = {
        isMultiSelect: true,
        isIndex: true,
        isShowOpera: false,
        showSummary: false,
        height: '20vh'
    };
    // 导入
    importData() {
        this.dialogVisible = false;
        const selectArr = JSON.parse(JSON.stringify(this.selectArray));
        const data = JSON.parse(JSON.stringify(this.gridData));
        this.importControls(selectArr, data, this.prevBillDetail);
    }
    // 获取采购单total

    // 不导入
    unImport() {
        this.dialogVisible = false;
        const data = JSON.parse(JSON.stringify(this.gridData));
        this.importControls([], data, this.prevBillDetail);
    }
    // 弹窗
    async showImportGoodsDialog({ prevBillUrl, prevBillId }, callback) {
        const res = await this._post({
            url: prevBillUrl,
            data: {
                data: {
                    id: prevBillId,
                    pageSize: -1
                    //   moduleId: this.$route.meta.moduleId
                }
            }
        });
        if (res.code === 0) {
            const { billGoodsList, ...other } = res.data;
            if (billGoodsList && billGoodsList.length === 0) {
                this.$message.warning('当前单据无货品需配货，请选择其他单据！');
                callback([], []);
                return;
            }
            this.dialogVisible = true;
            this.importControls = callback;
            this.gridData = billGoodsList;
            this.prevBillDetail = other;
            this.$nextTick(() => {
                ((this.$refs['GoodsTable'] as any).$refs['table'] as any).toggleAllSelection();
            });
        }
    }
    selectRow({ section }) {
        this.selectArray = section;
    }
}
</script>

<style scoped></style>
